﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NutriFast
{
    public partial class DietaDel : Form
    {
        public DietaDel()
        {
            InitializeComponent();
        }

        private void DietaDel_Load(object sender, EventArgs e)
        {
            name_TextChanged(null, null);
        }

        private void name_TextChanged(object sender, EventArgs e)
        {
            spVicListarDietasTableAdapter.Fill(this.dsListarDietas.spVicListarDietas, this.name.Text);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, "¿Seguro que desea eliminar?", "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {

                int index = dataGridView1.CurrentRow.Index;
                int id_seleccion = int.Parse("" + dataGridView1.Rows[index].Cells[0].Value);
                if (dbVic.eliminarDieta(id_seleccion))
                {
                    MessageBox.Show(this, "Dieta Eliminada", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    this.spVicListarDietasTableAdapter.Fill(this.dsListarDietas.spVicListarDietas, this.name.Text);
                    if (this.dataGridView1.Rows.Count == 0)
                        this.button1.Enabled = false;
                    else
                        this.button1.Enabled = true;

                }
                else
                    MessageBox.Show(this, "Error al eliminar dieta", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
    }
}
